﻿using System;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;

namespace YJKRevitDimensionText.DimCreator
{
	internal class CombinedDimensionOperation : HYCmdEntry
	{
		public CombinedDimensionOperation(ExternalCommandData commandData) : base(commandData)
		{
		}

		public void Excute()
		{
			try
			{
				RevitVersionFuncs.ClearSelection(this.m_sel);
				for (;;)
				{
					PickedBox pickedBox = null;
					try
					{
						pickedBox = this.m_sel.PickBox((Autodesk.Revit.UI.Selection.PickBoxStyle)0, "框选要合并的对齐标注");
					}
					catch (Exception)
					{
						break;
					}
					double x = pickedBox.Min.X;
					double x2 = pickedBox.Max.X;
					if (x > x2)
					{
						x = pickedBox.Max.X;
						x2 = pickedBox.Min.X;
					}
					double y = pickedBox.Min.Y;
					double y2 = pickedBox.Max.Y;
					if (y > y2)
					{
						y = pickedBox.Max.Y;
						y2 = pickedBox.Min.Y;
					}
					UV min = new UV(x, y);
					UV max = new UV(x2, y2);
					new CombinedDimension(this.m_doc, max, min).Combined();
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("合并区间出错！");
			}
		}
	}
}
